#!/bin/bash
current_dir=`pwd`
repo_name=".repo"
wcopy_name=".vsync_workingcopy"

if [ "$1" == "--help" ] ; then
echo "usage: uninstall [--purge]"
echo "--purge	removes also confuguration and user data"
exit 0
fi

if [ "$1" == "--purge" ] ; then
	#delete workingcopy and repository
	echo "------Removing vSync Configuration------"
	echo "Stopping svnserve..."
	/etc/init.d/svnserve stop
	echo "svnserve stopped!"
	rm -rf $HOME/$repo_name
	rm -rf $HOME/$wcopy_name
	#delete configurations
	rm -rf /var/run/vsync.state
	rm -rf /etc/vsync
	#delete webappconfigurations
	rm -rf /etc/apache2/ssl/server.crt
	rm -rf /etc/apache2/ssl/server.key
fi

	echo "--------REMOVING VSYNC-----------"
	vsync stop 2> /dev/null
	cd ./versionSync
	cat .vsync.txt | xargs rm -rf
	rm -rf /usr/bin/vsync
	echo "--------REMOVING VSYNCWEBAPP-----------"
	rm -rf /var/www/versionSyncWebApp
	rm -rf /var/www/media
	/etc/init.d/apache2 restart
	echo "--------REMOVING DEPENDENCIES-----------"
	cd ./import
	cd ./iCalendar-1.2
	cat .icalendar.txt | xargs rm -rf
	cd $current_dir


